/*
-------------------------------------------------------------------
BIE is Copyright 2001-2003 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
*/
package com.webdeninteractive.sbie.v1_1.util.xmlsvelte;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;

public class DOMUtil {
    
    /** Returns the concatenated text nodes contained under the given element.
     *  This method does no whitespace trimming of the text nodes.
     */
    public static String getTextContentNoTrim( Element e ) {
        StringBuffer ret = new StringBuffer();
        NodeList nl = e.getChildNodes();
        for( int i=0; i<nl.getLength(); i++ ) {
            Node n = nl.item(i);
            if ( n.getNodeType() == Node.TEXT_NODE ) {
                ret.append( n.getNodeValue() );
            }
        }
        return ret.toString();
        
    } // getTextContentNoTrim()
    
    /** Returns the concatenated text nodes containted under the given element.
     *  The returned text will be trimmed for leading/trailing whitespace.
     */
    public static String getTextContent( Element e ) {
        String s = getTextContentNoTrim(e);
        if (s!=null) {
            s = s.trim();
        }
        return s;
        
    } // getTextContent()
    

}
